/**
 * 
 */
package com.geezdata.cps.ttk.common.enums;

import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.geezdata.cps.base.enums.ErrorCode;
import com.geezdata.cps.base.exceptions.MyException;
import com.geezdata.cps.ttk.common.constants.JobClassNameConstants;

/**
 * @author sszheng
 * @date 创建时间：2017年9月26日 下午5:08:40
 *
 */
public enum JobTypeEnum {
	COMMON_JOB(1, JobClassNameConstants.DEFAULT_JOB_NAME),
	FIX_FAILED_TASK_JOB(2, JobClassNameConstants.FIX_FAILED_TASK_JOB_NAME),
	MOCK_DATA_JOB(3, JobClassNameConstants.MOCK_DATA_JOB),
	CREATE_TASK_JOB(4, JobClassNameConstants.CREATE_ORDER_SYNC_TASK_JOB),
	SAMPLE_JOB(100, JobClassNameConstants.SAMPLE_JOB_NAME);
	
    private Integer code;
    private String jobClassName;
    private static final Logger logger = LoggerFactory.getLogger(JobTypeEnum.class);
    
    JobTypeEnum(Integer code, String jobClassName) {
        this.code = code;
        this.jobClassName = jobClassName;
    }

	public int getCode() {
		return this.code;
	}
	
	public String getJobClassName() {
		return jobClassName;
	}

	public void setJobClassName(String jobClassName) {
		this.jobClassName = jobClassName;
	}

	public String getTriggerName(String desc) {
		return desc + "-" + UUID.randomUUID().toString();
	}
	
	public static JobTypeEnum getByCode(Integer code) {
        for (JobTypeEnum jobTypeEnum : values()) {
            if (jobTypeEnum.getCode() == code.intValue()) {
                return jobTypeEnum;
            }
        }
        
        logger.error( "Job type not exists.Code is " + code);
        throw new MyException(ErrorCode.INTERNAL_SERVER_ERROR);
    }
}
